﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMK.Paket_Tracker.Runtime;
using System.Windows.Controls;
using System.Windows.Input;
using MMK.Paket_Tracker.Runtime.Commands;
using MMK.Paket_Tracker.Runtime.BusinessEntities;


namespace MMK.Paket_Tracker.GUI.ViewModels
{
    /// <summary>
    /// 
    /// </summary>
    public class StartWindowViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="StartWindowViewModel"/> class.
        /// </summary>
        /// <param name="owner">The owner.</param>
        public StartWindowViewModel(UserControl owner)
        {
            this.owner = owner;
            PrepareCommands();
        }

        private void PrepareCommands()
        {
            CommandBinding getStatus = new CommandBinding(PTCommands.GetStatus);
            CommandBinding newPacket = new CommandBinding(PTCommands.NewPacket);

            getStatus.Executed += getStatus_Executed;
            getStatus.CanExecute += getStatus_CanExecute;

            newPacket.Executed += newPacket_Executed;
            newPacket.CanExecute += newPacket_CanExecute;

            owner.CommandBindings.Add(newPacket);
            owner.CommandBindings.Add(getStatus);
        }

        private void getStatus_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void getStatus_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            NotifyMainWindow(new MainWindowNotification(((UserControl)sender).Name,null,(RoutedUICommand)e.Command));
        }

        private void newPacket_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        private void newPacket_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            NotifyMainWindow(new MainWindowNotification(((UserControl)sender).Name, null, (RoutedUICommand)e.Command));
        }

        
    }
}
